<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Vue版本计算器</h1>
<div>
    <input type="text" v-model="num1">
    <input type="text" v-model="num2">
    <input type="button" value="加" @click="f(1)">
    <input type="button" value="减" @click="f(2)">
    <input type="button" value="乘" @click="f(3)">
    <input type="button" value="除" @click="f(4)">
    <h3>结果:{{info}}</h3>
</div>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
            num1:"",
            num2:"",
            info:""
        },
        methods:{
            f:function (x) {
                if(isNaN(v.num1)||isNaN(v.num2)){
                    v.info="输入错误!";
                    return;
                }
                switch (x) {
                    case 1:
                        v.info = v.num1*1+v.num2*1;
                        break;
                    case 2:
                        v.info = v.num1-v.num2;
                        break;
                    case 3:
                        v.info = v.num1*v.num2;
                        break;
                    case 4:
                        v.info = v.num1/v.num2;
                        break;
                }
            }
        }
    })
</script>
</body>
</html>